{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys\n",
    "sys.path.append(\"../\")\n",
    "from test_model import model\n",
    "model_rev = model\n",
    "# model_rev.summary()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [],
   "source": [
    "map_arr = [('conv1/conv ', 'conv2d_120 '), ('conv1/bn ', 'batch_normalization_121 '), ('conv1/relu ', 're_lu_121 '), ('zero_padding2d_9 ', 'zero_padding2d_3 '), ('pool1 ', 'max_pooling2d_1 '), ('conv2_block1_0_bn ', 'batch_normalization_122 '), ('conv2_block1_0_relu ', 're_lu_122 '), ('conv2_block1_1_conv ', 'conv2d_121 '), ('conv2_block1_1_bn ', 'batch_normalization_123 '), ('conv2_block1_1_relu ', 're_lu_123 '), ('conv2_block1_2_conv ', 'conv2d_122 '), ('conv2_block1_concat ', 'concatenate_58 '), ('conv2_block2_0_bn ', 'batch_normalization_124 '), ('conv2_block2_0_relu ', 're_lu_124 '), ('conv2_block2_1_conv ', 'conv2d_123 '), ('conv2_block2_1_bn ', 'batch_normalization_125 '), ('conv2_block2_1_relu ', 're_lu_125 '), ('conv2_block2_2_conv ', 'conv2d_124 '), ('conv2_block2_concat ', 'concatenate_59 '), ('conv2_block3_0_bn ', 'batch_normalization_126 '), ('conv2_block3_0_relu ', 're_lu_126 '), ('conv2_block3_1_conv ', 'conv2d_125 '), ('conv2_block3_1_bn ', 'batch_normalization_127 '), ('conv2_block3_1_relu ', 're_lu_127 '), ('conv2_block3_2_conv ', 'conv2d_126 '), ('conv2_block3_concat ', 'concatenate_60 '), ('conv2_block4_0_bn ', 'batch_normalization_128 '), ('conv2_block4_0_relu ', 're_lu_128 '), ('conv2_block4_1_conv ', 'conv2d_127 '), ('conv2_block4_1_bn ', 'batch_normalization_129 '), ('conv2_block4_1_relu ', 're_lu_129 '), ('conv2_block4_2_conv ', 'conv2d_128 '), ('conv2_block4_concat ', 'concatenate_61 '), ('conv2_block5_0_bn ', 'batch_normalization_130 '), ('conv2_block5_0_relu ', 're_lu_130 '), ('conv2_block5_1_conv ', 'conv2d_129 '), ('conv2_block5_1_bn ', 'batch_normalization_131 '), ('conv2_block5_1_relu ', 're_lu_131 '), ('conv2_block5_2_conv ', 'conv2d_130 '), ('conv2_block5_concat ', 'concatenate_62 '), ('conv2_block6_0_bn ', 'batch_normalization_132 '), ('conv2_block6_0_relu ', 're_lu_132 '), ('conv2_block6_1_conv ', 'conv2d_131 '), ('conv2_block6_1_bn ', 'batch_normalization_133 '), ('conv2_block6_1_relu ', 're_lu_133 '), ('conv2_block6_2_conv ', 'conv2d_132 '), ('conv2_block6_concat ', 'concatenate_63 '), ('pool2_bn ', 'batch_normalization_134 '), ('pool2_relu ', 're_lu_134 '), ('pool2_conv ', 'conv2d_133 '), ('pool2_pool ', 'average_pooling2d_3 '), ('conv3_block1_0_bn ', 'batch_normalization_135 '), ('conv3_block1_0_relu ', 're_lu_135 '), ('conv3_block1_1_conv ', 'conv2d_134 '), ('conv3_block1_1_bn ', 'batch_normalization_136 '), ('conv3_block1_1_relu ', 're_lu_136 '), ('conv3_block1_2_conv ', 'conv2d_135 '), ('conv3_block1_concat ', 'concatenate_64 '), ('conv3_block2_0_bn ', 'batch_normalization_137 '), ('conv3_block2_0_relu ', 're_lu_137 '), ('conv3_block2_1_conv ', 'conv2d_136 '), ('conv3_block2_1_bn ', 'batch_normalization_138 '), ('conv3_block2_1_relu ', 're_lu_138 '), ('conv3_block2_2_conv ', 'conv2d_137 '), ('conv3_block2_concat ', 'concatenate_65 '), ('conv3_block3_0_bn ', 'batch_normalization_139 '), ('conv3_block3_0_relu ', 're_lu_139 '), ('conv3_block3_1_conv ', 'conv2d_138 '), ('conv3_block3_1_bn ', 'batch_normalization_140 '), ('conv3_block3_1_relu ', 're_lu_140 '), ('conv3_block3_2_conv ', 'conv2d_139 '), ('conv3_block3_concat ', 'concatenate_66 '), ('conv3_block4_0_bn ', 'batch_normalization_141 '), ('conv3_block4_0_relu ', 're_lu_141 '), ('conv3_block4_1_conv ', 'conv2d_140 '), ('conv3_block4_1_bn ', 'batch_normalization_142 '), ('conv3_block4_1_relu ', 're_lu_142 '), ('conv3_block4_2_conv ', 'conv2d_141 '), ('conv3_block4_concat ', 'concatenate_67 '), ('conv3_block5_0_bn ', 'batch_normalization_143 '), ('conv3_block5_0_relu ', 're_lu_143 '), ('conv3_block5_1_conv ', 'conv2d_142 '), ('conv3_block5_1_bn ', 'batch_normalization_144 '), ('conv3_block5_1_relu ', 're_lu_144 '), ('conv3_block5_2_conv ', 'conv2d_143 '), ('conv3_block5_concat ', 'concatenate_68 '), ('conv3_block6_0_bn ', 'batch_normalization_145 '), ('conv3_block6_0_relu ', 're_lu_145 '), ('conv3_block6_1_conv ', 'conv2d_144 '), ('conv3_block6_1_bn ', 'batch_normalization_146 '), ('conv3_block6_1_relu ', 're_lu_146 '), ('conv3_block6_2_conv ', 'conv2d_145 '), ('conv3_block6_concat ', 'concatenate_69 '), ('conv3_block7_0_bn ', 'batch_normalization_147 '), ('conv3_block7_0_relu ', 're_lu_147 '), ('conv3_block7_1_conv ', 'conv2d_146 '), ('conv3_block7_1_bn ', 'batch_normalization_148 '), ('conv3_block7_1_relu ', 're_lu_148 '), ('conv3_block7_2_conv ', 'conv2d_147 '), ('conv3_block7_concat ', 'concatenate_70 '), ('conv3_block8_0_bn ', 'batch_normalization_149 '), ('conv3_block8_0_relu ', 're_lu_149 '), ('conv3_block8_1_conv ', 'conv2d_148 '), ('conv3_block8_1_bn ', 'batch_normalization_150 '), ('conv3_block8_1_relu ', 're_lu_150 '), ('conv3_block8_2_conv ', 'conv2d_149 '), ('conv3_block8_concat ', 'concatenate_71 '), ('conv3_block9_0_bn ', 'batch_normalization_151 '), ('conv3_block9_0_relu ', 're_lu_151 '), ('conv3_block9_1_conv ', 'conv2d_150 '), ('conv3_block9_1_bn ', 'batch_normalization_152 '), ('conv3_block9_1_relu ', 're_lu_152 '), ('conv3_block9_2_conv ', 'conv2d_151 '), ('conv3_block9_concat ', 'concatenate_72 '), ('conv3_block10_0_bn ', 'batch_normalization_153 '), ('conv3_block10_0_relu ', 're_lu_153 '), ('conv3_block10_1_conv ', 'conv2d_152 '), ('conv3_block10_1_bn ', 'batch_normalization_154 '), ('conv3_block10_1_relu ', 're_lu_154 '), ('conv3_block10_2_conv ', 'conv2d_153 '), ('conv3_block10_concat ', 'concatenate_73 '), ('conv3_block11_0_bn ', 'batch_normalization_155 '), ('conv3_block11_0_relu ', 're_lu_155 '), ('conv3_block11_1_conv ', 'conv2d_154 '), ('conv3_block11_1_bn ', 'batch_normalization_156 '), ('conv3_block11_1_relu ', 're_lu_156 '), ('conv3_block11_2_conv ', 'conv2d_155 '), ('conv3_block11_concat ', 'concatenate_74 '), ('conv3_block12_0_bn ', 'batch_normalization_157 '), ('conv3_block12_0_relu ', 're_lu_157 '), ('conv3_block12_1_conv ', 'conv2d_156 '), ('conv3_block12_1_bn ', 'batch_normalization_158 '), ('conv3_block12_1_relu ', 're_lu_158 '), ('conv3_block12_2_conv ', 'conv2d_157 '), ('conv3_block12_concat ', 'concatenate_75 '), ('pool3_bn ', 'batch_normalization_159 '), ('pool3_relu ', 're_lu_159 '), ('pool3_conv ', 'conv2d_158 '), ('pool3_pool ', 'average_pooling2d_4 '), ('conv4_block1_0_bn ', 'batch_normalization_160 '), ('conv4_block1_0_relu ', 're_lu_160 '), ('conv4_block1_1_conv ', 'conv2d_159 '), ('conv4_block1_1_bn ', 'batch_normalization_161 '), ('conv4_block1_1_relu ', 're_lu_161 '), ('conv4_block1_2_conv ', 'conv2d_160 '), ('conv4_block1_concat ', 'concatenate_76 '), ('conv4_block2_0_bn ', 'batch_normalization_162 '), ('conv4_block2_0_relu ', 're_lu_162 '), ('conv4_block2_1_conv ', 'conv2d_161 '), ('conv4_block2_1_bn ', 'batch_normalization_163 '), ('conv4_block2_1_relu ', 're_lu_163 '), ('conv4_block2_2_conv ', 'conv2d_162 '), ('conv4_block2_concat ', 'concatenate_77 '), ('conv4_block3_0_bn ', 'batch_normalization_164 '), ('conv4_block3_0_relu ', 're_lu_164 '), ('conv4_block3_1_conv ', 'conv2d_163 '), ('conv4_block3_1_bn ', 'batch_normalization_165 '), ('conv4_block3_1_relu ', 're_lu_165 '), ('conv4_block3_2_conv ', 'conv2d_164 '), ('conv4_block3_concat ', 'concatenate_78 '), ('conv4_block4_0_bn ', 'batch_normalization_166 '), ('conv4_block4_0_relu ', 're_lu_166 '), ('conv4_block4_1_conv ', 'conv2d_165 '), ('conv4_block4_1_bn ', 'batch_normalization_167 '), ('conv4_block4_1_relu ', 're_lu_167 '), ('conv4_block4_2_conv ', 'conv2d_166 '), ('conv4_block4_concat ', 'concatenate_79 '), ('conv4_block5_0_bn ', 'batch_normalization_168 '), ('conv4_block5_0_relu ', 're_lu_168 '), ('conv4_block5_1_conv ', 'conv2d_167 '), ('conv4_block5_1_bn ', 'batch_normalization_169 '), ('conv4_block5_1_relu ', 're_lu_169 '), ('conv4_block5_2_conv ', 'conv2d_168 '), ('conv4_block5_concat ', 'concatenate_80 '), ('conv4_block6_0_bn ', 'batch_normalization_170 '), ('conv4_block6_0_relu ', 're_lu_170 '), ('conv4_block6_1_conv ', 'conv2d_169 '), ('conv4_block6_1_bn ', 'batch_normalization_171 '), ('conv4_block6_1_relu ', 're_lu_171 '), ('conv4_block6_2_conv ', 'conv2d_170 '), ('conv4_block6_concat ', 'concatenate_81 '), ('conv4_block7_0_bn ', 'batch_normalization_172 '), ('conv4_block7_0_relu ', 're_lu_172 '), ('conv4_block7_1_conv ', 'conv2d_171 '), ('conv4_block7_1_bn ', 'batch_normalization_173 '), ('conv4_block7_1_relu ', 're_lu_173 '), ('conv4_block7_2_conv ', 'conv2d_172 '), ('conv4_block7_concat ', 'concatenate_82 '), ('conv4_block8_0_bn ', 'batch_normalization_174 '), ('conv4_block8_0_relu ', 're_lu_174 '), ('conv4_block8_1_conv ', 'conv2d_173 '), ('conv4_block8_1_bn ', 'batch_normalization_175 '), ('conv4_block8_1_relu ', 're_lu_175 '), ('conv4_block8_2_conv ', 'conv2d_174 '), ('conv4_block8_concat ', 'concatenate_83 '), ('conv4_block9_0_bn ', 'batch_normalization_176 '), ('conv4_block9_0_relu ', 're_lu_176 '), ('conv4_block9_1_conv ', 'conv2d_175 '), ('conv4_block9_1_bn ', 'batch_normalization_177 '), ('conv4_block9_1_relu ', 're_lu_177 '), ('conv4_block9_2_conv ', 'conv2d_176 '), ('conv4_block9_concat ', 'concatenate_84 '), ('conv4_block10_0_bn ', 'batch_normalization_178 '), ('conv4_block10_0_relu ', 're_lu_178 '), ('conv4_block10_1_conv ', 'conv2d_177 '), ('conv4_block10_1_bn ', 'batch_normalization_179 '), ('conv4_block10_1_relu ', 're_lu_179 '), ('conv4_block10_2_conv ', 'conv2d_178 '), ('conv4_block10_concat ', 'concatenate_85 '), ('conv4_block11_0_bn ', 'batch_normalization_180 '), ('conv4_block11_0_relu ', 're_lu_180 '), ('conv4_block11_1_conv ', 'conv2d_179 '), ('conv4_block11_1_bn ', 'batch_normalization_181 '), ('conv4_block11_1_relu ', 're_lu_181 '), ('conv4_block11_2_conv ', 'conv2d_180 '), ('conv4_block11_concat ', 'concatenate_86 '), ('conv4_block12_0_bn ', 'batch_normalization_182 '), ('conv4_block12_0_relu ', 're_lu_182 '), ('conv4_block12_1_conv ', 'conv2d_181 '), ('conv4_block12_1_bn ', 'batch_normalization_183 '), ('conv4_block12_1_relu ', 're_lu_183 '), ('conv4_block12_2_conv ', 'conv2d_182 '), ('conv4_block12_concat ', 'concatenate_87 '), ('conv4_block13_0_bn ', 'batch_normalization_184 '), ('conv4_block13_0_relu ', 're_lu_184 '), ('conv4_block13_1_conv ', 'conv2d_183 '), ('conv4_block13_1_bn ', 'batch_normalization_185 '), ('conv4_block13_1_relu ', 're_lu_185 '), ('conv4_block13_2_conv ', 'conv2d_184 '), ('conv4_block13_concat ', 'concatenate_88 '), ('conv4_block14_0_bn ', 'batch_normalization_186 '), ('conv4_block14_0_relu ', 're_lu_186 '), ('conv4_block14_1_conv ', 'conv2d_185 '), ('conv4_block14_1_bn ', 'batch_normalization_187 '), ('conv4_block14_1_relu ', 're_lu_187 '), ('conv4_block14_2_conv ', 'conv2d_186 '), ('conv4_block14_concat ', 'concatenate_89 '), ('conv4_block15_0_bn ', 'batch_normalization_188 '), ('conv4_block15_0_relu ', 're_lu_188 '), ('conv4_block15_1_conv ', 'conv2d_187 '), ('conv4_block15_1_bn ', 'batch_normalization_189 '), ('conv4_block15_1_relu ', 're_lu_189 '), ('conv4_block15_2_conv ', 'conv2d_188 '), ('conv4_block15_concat ', 'concatenate_90 '), ('conv4_block16_0_bn ', 'batch_normalization_190 '), ('conv4_block16_0_relu ', 're_lu_190 '), ('conv4_block16_1_conv ', 'conv2d_189 '), ('conv4_block16_1_bn ', 'batch_normalization_191 '), ('conv4_block16_1_relu ', 're_lu_191 '), ('conv4_block16_2_conv ', 'conv2d_190 '), ('conv4_block16_concat ', 'concatenate_91 '), ('conv4_block17_0_bn ', 'batch_normalization_192 '), ('conv4_block17_0_relu ', 're_lu_192 '), ('conv4_block17_1_conv ', 'conv2d_191 '), ('conv4_block17_1_bn ', 'batch_normalization_193 '), ('conv4_block17_1_relu ', 're_lu_193 '), ('conv4_block17_2_conv ', 'conv2d_192 '), ('conv4_block17_concat ', 'concatenate_92 '), ('conv4_block18_0_bn ', 'batch_normalization_194 '), ('conv4_block18_0_relu ', 're_lu_194 '), ('conv4_block18_1_conv ', 'conv2d_193 '), ('conv4_block18_1_bn ', 'batch_normalization_195 '), ('conv4_block18_1_relu ', 're_lu_195 '), ('conv4_block18_2_conv ', 'conv2d_194 '), ('conv4_block18_concat ', 'concatenate_93 '), ('conv4_block19_0_bn ', 'batch_normalization_196 '), ('conv4_block19_0_relu ', 're_lu_196 '), ('conv4_block19_1_conv ', 'conv2d_195 '), ('conv4_block19_1_bn ', 'batch_normalization_197 '), ('conv4_block19_1_relu ', 're_lu_197 '), ('conv4_block19_2_conv ', 'conv2d_196 '), ('conv4_block19_concat ', 'concatenate_94 '), ('conv4_block20_0_bn ', 'batch_normalization_198 '), ('conv4_block20_0_relu ', 're_lu_198 '), ('conv4_block20_1_conv ', 'conv2d_197 '), ('conv4_block20_1_bn ', 'batch_normalization_199 '), ('conv4_block20_1_relu ', 're_lu_199 '), ('conv4_block20_2_conv ', 'conv2d_198 '), ('conv4_block20_concat ', 'concatenate_95 '), ('conv4_block21_0_bn ', 'batch_normalization_200 '), ('conv4_block21_0_relu ', 're_lu_200 '), ('conv4_block21_1_conv ', 'conv2d_199 '), ('conv4_block21_1_bn ', 'batch_normalization_201 '), ('conv4_block21_1_relu ', 're_lu_201 '), ('conv4_block21_2_conv ', 'conv2d_200 '), ('conv4_block21_concat ', 'concatenate_96 '), ('conv4_block22_0_bn ', 'batch_normalization_202 '), ('conv4_block22_0_relu ', 're_lu_202 '), ('conv4_block22_1_conv ', 'conv2d_201 '), ('conv4_block22_1_bn ', 'batch_normalization_203 '), ('conv4_block22_1_relu ', 're_lu_203 '), ('conv4_block22_2_conv ', 'conv2d_202 '), ('conv4_block22_concat ', 'concatenate_97 '), ('conv4_block23_0_bn ', 'batch_normalization_204 '), ('conv4_block23_0_relu ', 're_lu_204 '), ('conv4_block23_1_conv ', 'conv2d_203 '), ('conv4_block23_1_bn ', 'batch_normalization_205 '), ('conv4_block23_1_relu ', 're_lu_205 '), ('conv4_block23_2_conv ', 'conv2d_204 '), ('conv4_block23_concat ', 'concatenate_98 '), ('conv4_block24_0_bn ', 'batch_normalization_206 '), ('conv4_block24_0_relu ', 're_lu_206 '), ('conv4_block24_1_conv ', 'conv2d_205 '), ('conv4_block24_1_bn ', 'batch_normalization_207 '), ('conv4_block24_1_relu ', 're_lu_207 '), ('conv4_block24_2_conv ', 'conv2d_206 '), ('conv4_block24_concat ', 'concatenate_99 '), ('pool4_bn ', 'batch_normalization_208 '), ('pool4_relu ', 're_lu_208 '), ('pool4_conv ', 'conv2d_207 '), ('pool4_pool ', 'average_pooling2d_5 '), ('conv5_block1_0_bn ', 'batch_normalization_209 '), ('conv5_block1_0_relu ', 're_lu_209 '), ('conv5_block1_1_conv ', 'conv2d_208 '), ('conv5_block1_1_bn ', 'batch_normalization_210 '), ('conv5_block1_1_relu ', 're_lu_210 '), ('conv5_block1_2_conv ', 'conv2d_209 '), ('conv5_block1_concat ', 'concatenate_100 '), ('conv5_block2_0_bn ', 'batch_normalization_211 '), ('conv5_block2_0_relu ', 're_lu_211 '), ('conv5_block2_1_conv ', 'conv2d_210 '), ('conv5_block2_1_bn ', 'batch_normalization_212 '), ('conv5_block2_1_relu ', 're_lu_212 '), ('conv5_block2_2_conv ', 'conv2d_211 '), ('conv5_block2_concat ', 'concatenate_101 '), ('conv5_block3_0_bn ', 'batch_normalization_213 '), ('conv5_block3_0_relu ', 're_lu_213 '), ('conv5_block3_1_conv ', 'conv2d_212 '), ('conv5_block3_1_bn ', 'batch_normalization_214 '), ('conv5_block3_1_relu ', 're_lu_214 '), ('conv5_block3_2_conv ', 'conv2d_213 '), ('conv5_block3_concat ', 'concatenate_102 '), ('conv5_block4_0_bn ', 'batch_normalization_215 '), ('conv5_block4_0_relu ', 're_lu_215 '), ('conv5_block4_1_conv ', 'conv2d_214 '), ('conv5_block4_1_bn ', 'batch_normalization_216 '), ('conv5_block4_1_relu ', 're_lu_216 '), ('conv5_block4_2_conv ', 'conv2d_215 '), ('conv5_block4_concat ', 'concatenate_103 '), ('conv5_block5_0_bn ', 'batch_normalization_217 '), ('conv5_block5_0_relu ', 're_lu_217 '), ('conv5_block5_1_conv ', 'conv2d_216 '), ('conv5_block5_1_bn ', 'batch_normalization_218 '), ('conv5_block5_1_relu ', 're_lu_218 '), ('conv5_block5_2_conv ', 'conv2d_217 '), ('conv5_block5_concat ', 'concatenate_104 '), ('conv5_block6_0_bn ', 'batch_normalization_219 '), ('conv5_block6_0_relu ', 're_lu_219 '), ('conv5_block6_1_conv ', 'conv2d_218 '), ('conv5_block6_1_bn ', 'batch_normalization_220 '), ('conv5_block6_1_relu ', 're_lu_220 '), ('conv5_block6_2_conv ', 'conv2d_219 '), ('conv5_block6_concat ', 'concatenate_105 '), ('conv5_block7_0_bn ', 'batch_normalization_221 '), ('conv5_block7_0_relu ', 're_lu_221 '), ('conv5_block7_1_conv ', 'conv2d_220 '), ('conv5_block7_1_bn ', 'batch_normalization_222 '), ('conv5_block7_1_relu ', 're_lu_222 '), ('conv5_block7_2_conv ', 'conv2d_221 '), ('conv5_block7_concat ', 'concatenate_106 '), ('conv5_block8_0_bn ', 'batch_normalization_223 '), ('conv5_block8_0_relu ', 're_lu_223 '), ('conv5_block8_1_conv ', 'conv2d_222 '), ('conv5_block8_1_bn ', 'batch_normalization_224 '), ('conv5_block8_1_relu ', 're_lu_224 '), ('conv5_block8_2_conv ', 'conv2d_223 '), ('conv5_block8_concat ', 'concatenate_107 '), ('conv5_block9_0_bn ', 'batch_normalization_225 '), ('conv5_block9_0_relu ', 're_lu_225 '), ('conv5_block9_1_conv ', 'conv2d_224 '), ('conv5_block9_1_bn ', 'batch_normalization_226 '), ('conv5_block9_1_relu ', 're_lu_226 '), ('conv5_block9_2_conv ', 'conv2d_225 '), ('conv5_block9_concat ', 'concatenate_108 '), ('conv5_block10_0_bn ', 'batch_normalization_227 '), ('conv5_block10_0_relu ', 're_lu_227 '), ('conv5_block10_1_conv ', 'conv2d_226 '), ('conv5_block10_1_bn ', 'batch_normalization_228 '), ('conv5_block10_1_relu ', 're_lu_228 '), ('conv5_block10_2_conv ', 'conv2d_227 '), ('conv5_block10_concat ', 'concatenate_109 '), ('conv5_block11_0_bn ', 'batch_normalization_229 '), ('conv5_block11_0_relu ', 're_lu_229 '), ('conv5_block11_1_conv ', 'conv2d_228 '), ('conv5_block11_1_bn ', 'batch_normalization_230 '), ('conv5_block11_1_relu ', 're_lu_230 '), ('conv5_block11_2_conv ', 'conv2d_229 '), ('conv5_block11_concat ', 'concatenate_110 '), ('conv5_block12_0_bn ', 'batch_normalization_231 '), ('conv5_block12_0_relu ', 're_lu_231 '), ('conv5_block12_1_conv ', 'conv2d_230 '), ('conv5_block12_1_bn ', 'batch_normalization_232 '), ('conv5_block12_1_relu ', 're_lu_232 '), ('conv5_block12_2_conv ', 'conv2d_231 '), ('conv5_block12_concat ', 'concatenate_111 '), ('conv5_block13_0_bn ', 'batch_normalization_233 '), ('conv5_block13_0_relu ', 're_lu_233 '), ('conv5_block13_1_conv ', 'conv2d_232 '), ('conv5_block13_1_bn ', 'batch_normalization_234 '), ('conv5_block13_1_relu ', 're_lu_234 '), ('conv5_block13_2_conv ', 'conv2d_233 '), ('conv5_block13_concat ', 'concatenate_112 '), ('conv5_block14_0_bn ', 'batch_normalization_235 '), ('conv5_block14_0_relu ', 're_lu_235 '), ('conv5_block14_1_conv ', 'conv2d_234 '), ('conv5_block14_1_bn ', 'batch_normalization_236 '), ('conv5_block14_1_relu ', 're_lu_236 '), ('conv5_block14_2_conv ', 'conv2d_235 '), ('conv5_block14_concat ', 'concatenate_113 '), ('conv5_block15_0_bn ', 'batch_normalization_237 '), ('conv5_block15_0_relu ', 're_lu_237 '), ('conv5_block15_1_conv ', 'conv2d_236 '), ('conv5_block15_1_bn ', 'batch_normalization_238 '), ('conv5_block15_1_relu ', 're_lu_238 '), ('conv5_block15_2_conv ', 'conv2d_237 '), ('conv5_block15_concat ', 'concatenate_114 '), ('conv5_block16_0_bn ', 'batch_normalization_239 '), ('conv5_block16_0_relu ', 're_lu_239 '), ('conv5_block16_1_conv ', 'conv2d_238 '), ('conv5_block16_1_bn ', 'batch_normalization_240 '), ('conv5_block16_1_relu ', 're_lu_240 '), ('conv5_block16_2_conv ', 'conv2d_239 '), ('conv5_block16_concat ', 'concatenate_115 '), ('bn ', 'batch_normalization_241 '), ('relu ', 're_lu_241 '), ('avg_pool ', 'global_average_pooling2d_1 '), ('predictions ', 'dense_1 ')]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "from tensorflow.keras import applications\n",
    "import numpy as np\n",
    "model = applications.ResNet50V2(weights=\"imagenet\")\n",
    "# model.summary()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "import tensorflow as tf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "predictions dense_1\n",
      "Output Loss:  0.0\n",
      "Weight Loss[0]:  0.0\n",
      "Weight Loss[1]:  0.0\n"
     ]
    }
   ],
   "source": [
    "for x in map_arr:\n",
    "    ori_layer, rev_layer = x\n",
    "    ori_layer = ori_layer.strip()\n",
    "    rev_layer = rev_layer.strip()\n",
    "    if len(model.get_layer(ori_layer).get_weights()) > 0:\n",
    "        # if(np.array(model_rev.get_layer(rev_layer).get_weights()).shape!=np.array(model.get_layer(ori_layer).get_weights()).shape):\n",
    "        #     print(ori_layer)\n",
    "        rlayer = model_rev.get_layer(rev_layer)\n",
    "        olayer = model.get_layer(ori_layer)\n",
    "        inp_shape = list(olayer.input_shape)\n",
    "        if None in olayer.input_shape:\n",
    "            inp_shape[0] = 1\n",
    "        inp = tf.constant(np.random.random(size=inp_shape))\n",
    "        # print()\n",
    "        if (olayer(inp) != rlayer(inp)).numpy().sum() != 0 and \"batch_normalization\" not in rev_layer:\n",
    "            print(ori_layer, rev_layer)\n",
    "            print(\"Output Loss: \", (olayer(inp) - model_rev.get_layer(\"softmax_1\")(rlayer(inp))).numpy().sum())\n",
    "            # print(olayer.get_config())\n",
    "            # print(rlayer.get_config())\n",
    "            print(\"Weight Loss[0]: \", np.array(olayer.get_weights()[0] - rlayer.get_weights()[0]).sum())\n",
    "            print(\"Weight Loss[1]: \", np.array(olayer.get_weights()[1] - rlayer.get_weights()[1]).sum())\n",
    "            # print(\"Weight Loss[2]: \", np.array(olayer.get_weights()[2] - rlayer.get_weights()[2]).sum())\n",
    "            # print(\"Weight Loss[3]: \", np.array(olayer.get_weights()[3] - rlayer.get_weights()[3]).sum())\n",
    "            \n",
    "            break\n",
    "        # break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">Processing... <span style=\"color: #f92672; text-decoration-color: #f92672\">━━━━</span><span style=\"color: #3a3a3a; text-decoration-color: #3a3a3a\">╺━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━</span> <span style=\"color: #800080; text-decoration-color: #800080\"> 11%</span> <span style=\"color: #008080; text-decoration-color: #008080\">0:00:23</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "Processing... \u001b[38;2;249;38;114m━━━━\u001b[0m\u001b[38;5;237m╺\u001b[0m\u001b[38;5;237m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[35m 11%\u001b[0m \u001b[36m0:00:23\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>\n"
      ],
      "text/plain": []
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "ename": "KeyboardInterrupt",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-5-0bea6b20399a>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m      9\u001b[0m \u001b[0;31m# for i  in range(n):\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     10\u001b[0m     \u001b[0minp\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mconstant\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrandom\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrandom\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msize\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0minp_shape\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 11\u001b[0;31m     \u001b[0;32mif\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mmodel\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minp\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m-\u001b[0m \u001b[0mmodel_rev\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minp\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnumpy\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msum\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m!=\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     12\u001b[0m         \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Unequal!\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda2/envs/detr/lib/python3.6/site-packages/keras/engine/base_layer.py\u001b[0m in \u001b[0;36m__call__\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m   1035\u001b[0m         with autocast_variable.enable_auto_cast_variables(\n\u001b[1;32m   1036\u001b[0m             self._compute_dtype_object):\n\u001b[0;32m-> 1037\u001b[0;31m           \u001b[0moutputs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcall_fn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minputs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   1038\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1039\u001b[0m         \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_activity_regularizer\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda2/envs/detr/lib/python3.6/site-packages/keras/engine/functional.py\u001b[0m in \u001b[0;36mcall\u001b[0;34m(self, inputs, training, mask)\u001b[0m\n\u001b[1;32m    413\u001b[0m     \"\"\"\n\u001b[1;32m    414\u001b[0m     return self._run_internal_graph(\n\u001b[0;32m--> 415\u001b[0;31m         inputs, training=training, mask=mask)\n\u001b[0m\u001b[1;32m    416\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    417\u001b[0m   \u001b[0;32mdef\u001b[0m \u001b[0mcompute_output_shape\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0minput_shape\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda2/envs/detr/lib/python3.6/site-packages/keras/engine/functional.py\u001b[0m in \u001b[0;36m_run_internal_graph\u001b[0;34m(self, inputs, training, mask)\u001b[0m\n\u001b[1;32m    548\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    549\u001b[0m         \u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mkwargs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnode\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmap_arguments\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtensor_dict\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 550\u001b[0;31m         \u001b[0moutputs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnode\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlayer\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    551\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    552\u001b[0m         \u001b[0;31m# Update tensor_dict.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda2/envs/detr/lib/python3.6/site-packages/keras/engine/base_layer.py\u001b[0m in \u001b[0;36m__call__\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m   1035\u001b[0m         with autocast_variable.enable_auto_cast_variables(\n\u001b[1;32m   1036\u001b[0m             self._compute_dtype_object):\n\u001b[0;32m-> 1037\u001b[0;31m           \u001b[0moutputs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcall_fn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minputs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   1038\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1039\u001b[0m         \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_activity_regularizer\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda2/envs/detr/lib/python3.6/site-packages/keras/layers/advanced_activations.py\u001b[0m in \u001b[0;36mcall\u001b[0;34m(self, inputs)\u001b[0m\n\u001b[1;32m    432\u001b[0m                         \u001b[0malpha\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnegative_slope\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    433\u001b[0m                         \u001b[0mmax_value\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmax_value\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 434\u001b[0;31m                         threshold=self.threshold)\n\u001b[0m\u001b[1;32m    435\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    436\u001b[0m   \u001b[0;32mdef\u001b[0m \u001b[0mget_config\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda2/envs/detr/lib/python3.6/site-packages/tensorflow/python/util/dispatch.py\u001b[0m in \u001b[0;36mwrapper\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m    204\u001b[0m     \u001b[0;34m\"\"\"Call target, and fall back on dispatchers if there is a TypeError.\"\"\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    205\u001b[0m     \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 206\u001b[0;31m       \u001b[0;32mreturn\u001b[0m \u001b[0mtarget\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    207\u001b[0m     \u001b[0;32mexcept\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mTypeError\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mValueError\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    208\u001b[0m       \u001b[0;31m# Note: convert_to_eager_tensor currently raises a ValueError, not a\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda2/envs/detr/lib/python3.6/site-packages/keras/backend.py\u001b[0m in \u001b[0;36mrelu\u001b[0;34m(x, alpha, max_value, threshold)\u001b[0m\n\u001b[1;32m   4710\u001b[0m     \u001b[0mclip_max\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mFalse\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   4711\u001b[0m   \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 4712\u001b[0;31m     \u001b[0mx\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnn\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrelu\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   4713\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   4714\u001b[0m   \u001b[0;32mif\u001b[0m \u001b[0mclip_max\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda2/envs/detr/lib/python3.6/site-packages/tensorflow/python/ops/gen_nn_ops.py\u001b[0m in \u001b[0;36mrelu\u001b[0;34m(features, name)\u001b[0m\n\u001b[1;32m  10476\u001b[0m     \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m  10477\u001b[0m       _result = pywrap_tfe.TFE_Py_FastPathExecute(\n\u001b[0;32m> 10478\u001b[0;31m         _ctx, \"Relu\", name, features)\n\u001b[0m\u001b[1;32m  10479\u001b[0m       \u001b[0;32mreturn\u001b[0m \u001b[0m_result\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m  10480\u001b[0m     \u001b[0;32mexcept\u001b[0m \u001b[0m_core\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_NotOkStatusException\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mKeyboardInterrupt\u001b[0m: "
     ]
    }
   ],
   "source": [
    "import tensorflow as tf\n",
    "import numpy as np\n",
    "from rich.progress import track\n",
    "import rich\n",
    "inp_shape = [1, 224, 224, 3]\n",
    "n = 100\n",
    "\n",
    "for n in track(range(n), description=\"Processing...\"):\n",
    "# for i  in range(n):\n",
    "    inp = tf.constant(np.random.random(size=inp_shape))\n",
    "    if (model(inp) - model_rev(inp)).numpy().sum() != 0:\n",
    "        print(\"Unequal!\")"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "e4cf0c2eb7cbcfa00f632b3c01815c72950e084f5a7f9a38559111bb17fddb5e"
  },
  "kernelspec": {
   "display_name": "Python 3.6.10 ('detr')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.10"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
